<script>

export default {
  name: "index",
  props: {
    title: {
      type: String,
      default: ''
    },
    icon: {
      type: String,
      default: null
    },
    lineColor: {
      type: String,
      default: '#f9a415'
    }
  },
  methods: {
    // 判断插槽是否为空
    isSlotEmpty(name) {
      return this.$slots[name] === undefined || this.$slots[name].length === 0
    }
  },
  computed: {
    isShowTitle() {
      return this.title !== '' || this.icon !== null || !this.isSlotEmpty('title-right') || this.$props.icon !== null;
    },
  }
}
</script>

<template>
  <view class="module-card">
    <view class="cell module-card__title" v-if="isShowTitle">
      <view class="cell-hd" v-if="icon">
        <u-icon :name="icon" size="22"></u-icon>
      </view>
      <view class="cell-hd" v-else>
        <view class="module-card__color-line" :style="{background: lineColor}"></view>
      </view>
      <view class="cell-bd module-card__title__text">{{title}}</view>
      <view class="cell-ft module-card__title__text">
        <slot name="title-right"></slot>
      </view>
    </view>
    <slot name="default"></slot>
  </view>
</template>

<style scoped lang="scss">
.module-card{
  margin-bottom: 10px;
  background-color: #fff;
  padding: 20px 20px 0px 20px;
  &:last-child{
    margin-bottom: 0px;
  }
  &__title{
    font-size: 16px;
    border-bottom: 1px solid #eee;
    color: #113d48;
    padding-bottom: 15px;
    margin-bottom: 15px;
    &__text{
      padding-left: 5px;
    }
  }
  &__color-line{
    width: 3px;
    height: 16px;
  }
}
.footer{
  position: fixed;
  left: 0px;
  right: 0px;
  bottom: 0px;
  z-index: 10;
  padding: 10px 5px;
  background: #fff;
  border-top: 1px solid #eee;
  .save{
    padding: 0 5px;
    button{
      min-width: 120px;
    }
  }
  .submit{
    padding: 0 5px;
    width: 100%;
  }
  button{
    margin: 0;
  }
}
</style>
